//路由配置：拦截器 ,重定向等
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const router = new VueRouter({
	mode:'history',
	routes:[
		{path:"/user/login",component:()=>import("../views/user/Login")},
		{path:"/user/register",component:()=>import("../views/user/Register")},
		//公共页面
		{
			path:'/Layout/home',
			//别名
      		// alias: "/",
			component:()=>import ("../views/Layout/Home")
		},
		{
			path:'/Layout/shopping',component:()=>import ("../views/Layout/Shopping")
		},
		{
			path:'/Layout/oeat',component:()=>import ("../views/Layout/Oeat")
		},
		{
			path:'/Layout/details',component:()=>import ("../views/Layout/Details")
		},
		{
			path:'/Layout/sc',
			component:()=>import ("../views/Layout/sc")
		},,
		{
			path:'/Layout/collection',
			meta:{isLogin:true},
			component:()=>import ("../views/Layout/Collection")
		},
		//重定向
		{
			path:"/",
			redirect:"/layout/home"
		},
		{
			path:'/404',compoent:()=>import("../views/404")
		},
		{
			path:"*",
			//通配符接受不存在的匹配地址
			redirect:"/404"
		}
	]
});
//路由守卫-路由生命周期-路由拦截器
router.beforeEach((to,from,next)=>{
	//路由变化的时候该函数就被执行了
  	//读取本地存储的用户标识-isLogin
  	//判断to的meta信息的权限是否符合用户的权限
	const isLogin = false;
	if(to.meta.isLogin && !isLogin){
		return next(false)
	}
	// console.log(to)
	// console.log(from);
	next()//默认参数true 运行跳转 false禁止跳转
})
export default router